﻿using Architecture.API.Application.TraceabilityCommand.BreedCommand;
using MediatR;
using Traceability.Domain.BreedDomain;
using Traceability.Domain.Service.BreedService;

namespace Architecture.API.Application.TraceabilityCommandHandler.BreedCommandHandler
{
    /// <summary>
    /// 添加养殖信息命令处理器
    /// </summary>
    public class AddBreedCommandHandler : IRequestHandler<AddBreedCommand, int>
    {
        /// <summary>
        /// 养殖服务
        /// </summary>
        protected readonly IBreedService breedService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="breedService">养殖服务</param>
        public AddBreedCommandHandler(IBreedService breedService)
        {
            this.breedService = breedService;
        }


        /// <summary>
        /// 添加养殖信息
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> Handle(AddBreedCommand request, CancellationToken cancellationToken)
        {
            return await breedService.AddBreed(new Breed() { Quality=request.Quality,Source=request.Source,FeedingDays=request.FeedingDays,FeedBrand=request.FeedBrand,BreedingManager=request.BreedingManager,DateOfSlaughter=request.DateOfSlaughter,ProductionBatch=request.ProductionBatch,ShoppingId=request.ShoppingId,CreatedBy=request.CreatedBy,CreatedDate=DateTime.Now });
        }
    }
}
